/*

Frequency of use: 1 [2] 3 4 5 MEDIUM LOW

Short:
    Builder is a class (or set of classes) responsible for constructing an 
object. Each builder constructs a different part of the object.    
        
Long:
    The Builder Pattern is a software design pattern. The intention is to 
abstract steps of construction of objects so that different implementations of 
these steps can construct different representations of objects.
Often, the Builder Pattern is used to build Products in accordance to the 
Composite pattern, a structure pattern.

Information sources:
 - http://calumgrant.net/patterns/index.html
 - http://en.wikipedia.org/wiki/Builder_pattern
 - http://www.dofactory.com/Patterns/Patterns.aspx
*/

#include <string>
#include <iostream>

class Message
{
public:
	std::string greeting, recipient;
	void send()
	{
		std::cout << greeting << " " << recipient << "!" << std::endl;
	}
};

class Builder
{
public:
	virtual ~Builder() { }
	virtual void build(Message & msg) const=0;
};

class Hello : public Builder
{
public:
	void build(Message & msg) const
	{
		msg.greeting = "Hello";
	}
};

class World : public Builder
{
public:
	void build(Message & msg) const
	{
		msg.recipient = "world";
	}
};

void hello_world(const Builder & stage1, const Builder & stage2)
{
	Message msg;
	stage1.build(msg);
	stage2.build(msg);
	msg.send();
}

int main()
{
	hello_world(Hello(), World());
	return 0;
}

